package com.ruoyi.system.task;


import com.ruoyi.system.domain.BdmOrder;
import com.ruoyi.system.domain.dto.BdmOrderPayDto;
import com.ruoyi.system.enums.BdmOrderEnum;
import com.ruoyi.system.service.IBdmOrderService;
import com.ruoyi.system.service.IDistributionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component("orderTask")
public class OrderTask {

    @Autowired
    private IBdmOrderService bdmOrderService;



    @Autowired
    private IDistributionService iDistributionService;

    //修改未支付超时的订单为已关闭
    public void closeOrder(){
        log.info("关闭未支付超时订单定时任务已执行");
        bdmOrderService.closeOrder();
        log.info("修改第三方支付订单,支付成功的为已完成,定时任务执行了....................................................");
        List<BdmOrder> list = bdmOrderService.lambdaQuery()
                .eq(BdmOrder::getOrderStatus, BdmOrderEnum.UNPAID.getType())
                .eq(BdmOrder::getPayType, BdmOrderEnum.THIRD_PARTY.getType()).list();
        for (BdmOrder bdmOrder : list) {
            BdmOrderPayDto bdmOrderPayDto = new BdmOrderPayDto();
            bdmOrderPayDto.setOrderId(bdmOrder.getId());
            bdmOrderPayDto.setPayMode(bdmOrder.getPayType());
            bdmOrderService.balancePay(bdmOrderPayDto);
        }
    }






    public void shipmentsQuery(){
        log.info("查询订单发货信息定时任务执行了....................................................");
        iDistributionService.shipmentsQuery();
    }

    /**
     * 十五天自动收货
     */
    public void takeDeliveryOfGoods(){
        log.info("自动收货定时任务执行了....................................................");
        bdmOrderService.takeDeliveryOfGoods();
    }
}
